package com.demo.function.excel.easyexcel.utils;

import com.alibaba.excel.EasyExcel;
import com.demo.function.excel.easyexcel.listener.ValidateListener;
import com.demo.function.excel.easyexcel.pojo.ValidateResult;

import java.io.InputStream;

public class ExcelReadUtil {

    /**
     * 导入操作
     * @param inputStream 文件流
     * @param head 表头对象
     * @param validate 是否校验
     * @param headRowNumber 跳过表头行数
     * @return
     * @param <T>
     */
    public static <T> ValidateResult<T> read(InputStream inputStream, Class<T> head, boolean validate, int headRowNumber) {
        ValidateListener<T> listener = new ValidateListener<>(validate);
        EasyExcel.read(inputStream, head, listener).headRowNumber(headRowNumber).sheet().doRead();
        return listener.getValidateResult();
    }
}
